home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Ken Long / NewDisplay-c / Think / NewDisplay.c next >
Encoding:
Text File  |  1994-12-04  |  10.6 KB  |  149 lines  |  [TEXT/KAHL]

  1.  
  2. //• Subject: Display a file program
  3. //• Message-ID: <1701@uw-beaver>
  4. //• Date: Wed, 6 Nov 85 22:18:16 MST
  5. //• Date-Received: Fri, 8 Nov 85 02:05:35 MST
  6. //• Sender: daemon@uw-beaver
  7. //• Organization: U of Washington Computer Science
  8. //• Lines: 372
  9.  
  10. //• From: kangaro!milo@Purdue.EDU
  11.  
  12. //• This is a little program I whipped up in Megamax C that will 
  13. //• display any Mac file of type TEXT.  It is very handy for looking 
  14. //• at text files you have downloaded from a BBS without having to 
  15. //• load a text editor.  The program loads in about 4 seconds and 
  16. //• supports standard Mac desk accessorys...etc.
  17.  
  18. //• Let me know if you have any problems with the program...the 
  19. //• source follows...
  20.  
  21. //• Greg Corson
  22. //• UUCP: {ihnp4 | ucbvax}!pur-ee!kangaro!milo
  23. //• ARPA: pur-ee!kangaro!milo@Purdue.ARPA
  24. //• EDU: kangaro!milo@ee.Purdue.EDU
  25. //• Or call my BBS at (219) 277-5825
  26.  
  27. //• This sample program allows a user to open a file and print 
  28. //• it's contents to a window on the Mac screen.  To give the 
  29. //• compiled program an Icon copy the resources from Display.rsrc 
  30. //• (use Rmover or Resource Editor) and paste them into the 
  31. //• compiled file.  Then use SetFile to change the creator name of 
  32. //• the compiled file to DFIL and set the bundle bit.  When you 
  33. //• return to the finder the program icon should have an icon.
  34.  
  35. //• By Greg Corson
  36. //• 19141 Summers Drive
  37. //• South Bend, IN 46637
  38. //• (219) 272-2136
  39. //• UUCP: {ihnp4 | ucbvax}!pur-ee!kangaro!milo
  40. //• ARPA: pur-ee!kangaro!milo@Purdue.ARPA
  41. //• EDU: kangaro!milo@ee.Purdue.EDU
  42. //• Or call my BBS at (219) 277-5825
  43.  
  44. #include <packages.h>
  45.  
  46. #define lastMenu      4
  47. #define appleMenu      1
  48. #define fileMenu    256
  49. #define editMenu    257
  50. #define stopMenu    258
  51.  
  52. RgnHandle        updateRgn;
  53. MenuHandle    myMenus[lastMenu+1];
  54. Rect            screenRect, dragRect, pRect;
  55. Boolean            doneFlag, temp;
  56. EventRecord        myEvent;
  57. short                code, refNum;
  58. WindowRecord    wRecord;
  59. WindowPtr        myWindow, whichWindow;
  60. GrafPtr            temPort;
  61. short                theMenu, theItem;
  62. short                fileOpen, wide, fd1;
  63. long            count;
  64. char            tempBuf[32];
  65.  
  66. void Center (char *str);
  67.  
  68. //•---------------------------------------------------------------------------*/
  69. //• This subroutine processes commands from the menu bar, where
  70. //• theMenu is the menu ID, theItem  is the item number in the menu.
  71.  
  72. void DoCommand (long mSelect)
  73. {
  74.     short theMenu = HiWord(mSelect);
  75.     short theItem = LoWord(mSelect);
  76.     char name[256];
  77.     SFReply rep;
  78.     SFTypeList typeList;
  79.     short i;
  80.  
  81.     Point openP = { 100, 60 };
  82.  
  83.     //• Switch to decide what menu the cursor is in.
  84.     switch (theMenu)
  85.     {
  86.         //• Mouse down in apple menu.
  87.         case appleMenu:    
  88.             //• Item one is the "about Display a file" box.
  89.             if (theItem == 1)
  90.             {
  91.                 TextFont (systemFont);
  92.                 TextSize (12);
  93.                 EraseRect (&pRect);
  94.                 MoveTo (pRect.left, pRect.top+70);
  95.                 Center ((char*) "\pDisplay a file program");
  96.                 Center ((char*) "\pCopyright 1985 by Greg Corson");
  97.                 Center ((char*) "\pKangaroo Koncepts, Inc.");
  98.                 Center ((char*) "\p19141 Summers Drive");
  99.                 Center ((char*) "\pSouth Bend, IN 46637");
  100.                 Center ((char*) "\p1(219) 277-5306");
  101.                 TextFont (monaco);
  102.                     TextSize (9);
  103.                 Move (0, -3);
  104.                 Center ((char*) "\pFeel free to give this program away to all your friends.");
  105.                 Center ((char*) "\pIt should NOT be sold for profit.  Be sure to try our");
  106.                 Center ((char*) "\pComputer Based Communications System \"The Connection\"");
  107.                 Center ((char*) "\pFree demo line (219) 277-5825 available 24 hours at 300 or");
  108.                 Center ((char*) "\p1200 baud.  Be sure to look at the \"MacTech\" special");
  109.                 Center ((char*) "\pinterest group for information of interest to Mac");
  110.                 Center ((char*) "\pprogrammers and the \"macintosh\" SIG for general info.");
  111.                 Center ((char*) "\pAnother old program \"brought back from the dead\"");
  112.                 Center ((char*) "\pby Ken Long, at itty bitty bytes™");
  113.                 Pretty ();
  114.                 MoveTo (pRect.left + 1, pRect.bottom - 2);
  115.             }
  116.             //• The rest of the items are desk accessorys.
  117.             else
  118.                 {
  119.                     GetItem (myMenus[1], theItem, name);
  120.                     refNum = OpenDeskAcc (name);
  121.                     SetPort (myWindow);
  122.             }
  123.         break;
  124.         
  125.         case fileMenu:    
  126.         //• Mouse down in file menu.
  127.             switch (theItem)
  128.             {
  129.                 case 1:        //• Open file.
  130.                     typeList[0] = 'TEXT';
  131.                     SFGetFile (openP, "\p", 0L, 1, typeList, 0L, &rep);
  132.                     if (rep.good)
  133.                     {
  134.                         //• Doesn't mess with DisableItem, etc.
  135.                         if (fileOpen)
  136.                         {
  137.                             FSClose (fd1);
  138.                             fileOpen = false;
  139.                         }
  140.                         if (FSOpen (rep.fName, rep.vRefNum, &fd1) == noErr)
  141.                         {
  142.                             ScrollRect (&pRect, 0, -11, updateRgn);
  143.                             fileOpen = true;
  144.                         }
  145.                     }
  146.                 break;
  147.     
  148.                 //• Close file.
  149.